package org.rambadger.command.resource;


import com.sun.jersey.api.NotFoundException;
import com.yammer.dropwizard.auth.Auth;
import org.mongojack.JacksonDBCollection;
import org.rambadger.command.auth.AuthUser;
import org.rambadger.command.axon.JCollection;
import org.hibernate.validator.constraints.NotEmpty;
import org.rambadger.command.representation.User;
import org.rambadger.command.view.UserView;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


@Path("/user/")
public class ViewUserResource {
    @JCollection(type=User.class)
    private JacksonDBCollection<User, String> users = null;


    @GET @Path("{userName}")
    @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON})
    public Object getUserList(@Auth(required = true) AuthUser authUser, @PathParam("userName") @NotEmpty String userName) {
        User user = users.findOneById(userName);
        if (user == null) {
            throw new NotFoundException();
        } else {
            return new UserView(authUser, user);
        }
    }
}

